<?php
// jSON URL which should be requested
$json_url = 'http://www.mathinstitutes.org/math-videos/curl_response.php';
 
$username = 'chingcui';  // authentication
$password = 'hello268';  // authentication
 
// jSON String for request
$data = array("name" => "Hagrid", "age" => "36");                                                                    
$json_string = "json=".json_encode($data);  
echo "Request: ".$json_string."<br>"; 
// Initializing curl
$ch = curl_init( $json_url );
 
// Configuring curl options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => 1,
//CURLOPT_USERPWD => $username . ":" . $password,   // authentication
//CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
CURLOPT_POSTFIELDS => $json_string
);
 
// Setting curl options
curl_setopt_array( $ch, $options );
 
// Getting results
$json_response =  curl_exec($ch); // Getting jSON result string
echo "Response: $json_response<br>";
print_r($json_response);
echo "<br>";
$obj=json_decode($json_response);
print_r($obj);
echo "<br>";
echo $obj["name"];
?>